package
{
	import com.code.Card;
	import com.code.CardFactory;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.errors.IOError;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	
	public class FirstNewProject extends Sprite
	{
		
		private var cardFactory:CardFactory;
		public function FirstNewProject()
		{
			load();
		}
		
		private function load():void
		{
			var loader:Loader = new Loader();
			loader.load(new URLRequest("source/pic/imageCard.png"));
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaderOverListener);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onLoaderErrorListener);
		}
		
		private function onLoaderErrorListener(event:IOErrorEvent):void
		{
			// TODO Auto-generated method stub
			trace(00);
		}
		
		private function onLoaderOverListener(event:Event):void
		{
			// TODO Auto-generated method stub
			event.currentTarget.removeEventListener(Event.COMPLETE,onLoaderOverListener);
			event.currentTarget.removeEventListener(IOErrorEvent.IO_ERROR,onLoaderErrorListener);
			cardFactory = new CardFactory(LoaderInfo(event.currentTarget).loader.content as Bitmap);
			LoaderInfo(event.currentTarget).loader.unload();
			init();
		}
		private function init():void
		{
			var arr:Array = cardFactory.getRandomCards();
			for(var i:int = 0;i<arr.length;i++)
			{
				var card:Card = arr[i] as Card;
				card.x = 20 * i;
				card.y = 50;
				addChild(card);
			}
		}
	}
}